package com.example.demo.JDBC;

import java.sql.*;

public class JdbcTest {
//    使用jdbc连接数据库
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
//        DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
        String url = "jdbc:mysql://localhost:3306/demo";
        String username = "root";
        String password = "12358";
        Connection conn = DriverManager.getConnection(url, username, password);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from student");
        while (rs.next()) {
            String id = rs.getString("id");
            String name = rs.getString("name");
            System.out.println("id: " + id + " name: " + name);
        }

        conn.close();
    }
}
